package com.atmc.controller;

import com.atmc.bean.Supplier;
import com.atmc.service.OpenFeignService;
import com.atmc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class SuppFeignController {
    @Autowired
    OpenFeignService openFeignService;

    @Autowired
    SupplierService supplierService;
    //首页跳转到供应商列表信息
    @RequestMapping("/supplier/noticetype-list")
    public String toNoticetypelist(Model model) {
        List<Supplier> list = openFeignService.supplierList();
        model.addAttribute("msg",list);
        return "supplier/noticetype-list";
    }

    //首页跳转到供应商管理信息
    @RequestMapping("/supplier/notice-list")
    public String toNoticelist(Model model) {
        List<Supplier> list = openFeignService.supplierList();
        model.addAttribute("msg",list);
        return "supplier/notice-list";
    }
    //供应商删除一条数据
    @RequestMapping("/tosupplierdelete/{supplier_id}")
    public String tosupplierdelete(@PathVariable("supplier_id")int supplier_id,Model model){
        supplierService.deleteOne(supplier_id);
        List<Supplier> list = openFeignService.supplierList();
        model.addAttribute("msg",list);
        return "supplier/notice-list";
    }
    //供应商修改一条数据
    @RequestMapping("/tosupplierupdate/{supplier_name}")
    public String tosupplierupdate(@PathVariable("supplier_name")String supplier_name, Model model){
        model.addAttribute("suppname",supplier_name);

        return "supplier/updatesupplier";
    }
    //供应商修改一条数据
    @RequestMapping("/after/updatesupplier")
    public String AfterUpdatesupplier(@RequestParam("supplier_name")String supplier_name,
                                      @RequestParam("linkman")String linkman,
                                      @RequestParam("phone")String phone,
                                      @RequestParam("email")String email
            ,Model model)
    {
        Supplier supplier=new Supplier(null,supplier_name,linkman,phone,email,null,null);
        supplierService.updateOne(supplier);
        List<Supplier> list = openFeignService.supplierList();
        model.addAttribute("msg",list);
        return "supplier/notice-list";
    }
}
